package com.news.servlet.admin;

import com.news.service.NewsService;
import com.news.service.impl.NewsServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/newsDelete")
public class NewsDeleteServlet extends HttpServlet {
    private NewsService newsService = new NewsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            // 获取新闻ID
            int newsId = Integer.parseInt(request.getParameter("id"));
            
            // 删除新闻
            if (newsService.deleteNews(newsId)) {
                request.getSession().setAttribute("message", "新闻删除成功！");
            } else {
                request.getSession().setAttribute("message", "新闻删除失败！");
            }
        } catch (Exception e) {
            request.getSession().setAttribute("message", "新闻删除失败：" + e.getMessage());
        }
        
        // 重定向回新闻管理页面
        response.sendRedirect(request.getContextPath() + "/admin/newsManage");
    }
} 